/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ManagePlanesView.java
 *
 * Created on 18.10.2011, 20:11:44
 */
package de.hdm.itproject.views;

import de.hdm.itproject.AboutBox;
import de.hdm.itproject.App;
import de.hdm.itproject.MainView;
import de.hdm.itproject.views.CreateNewPlaneDialog;
import java.awt.BorderLayout;
import javax.swing.JDialog;
import javax.swing.JFrame;
import org.jdesktop.application.FrameView;

/**
 *
 * @author tim
 */
public class ManagePlanesView extends javax.swing.JPanel {

    /** Creates new form ManagePlanesView */
    public ManagePlanesView() {
        initComponents();
        //this.setSize(App.getApplication().getMainFrame().);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("de.hdm.itprojectPU").createEntityManager();
        planeQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT p FROM Plane p");
        planeList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : planeQuery.getResultList();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblManagePlanesTable = new javax.swing.JTable();
        btnManagePlanesViewOk = new javax.swing.JButton();
        btnManagePlanesViewAdd = new javax.swing.JButton();

        setName("Form"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tblManagePlanesTable.setName("tblManagePlanesTable"); // NOI18N

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, planeList, tblManagePlanesTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${type}"));
        columnBinding.setColumnName("Type");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${seats}"));
        columnBinding.setColumnName("Seats");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
        columnBinding.setColumnName("Id");
        columnBinding.setColumnClass(Integer.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(tblManagePlanesTable);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(de.hdm.itproject.App.class).getContext().getResourceMap(ManagePlanesView.class);
        btnManagePlanesViewOk.setText(resourceMap.getString("btnManagePlanesViewOk.text")); // NOI18N
        btnManagePlanesViewOk.setName("btnManagePlanesViewOk"); // NOI18N
        btnManagePlanesViewOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnManagePlanesViewOkActionPerformed(evt);
            }
        });

        btnManagePlanesViewAdd.setText(resourceMap.getString("btnManagePlanesViewAdd.text")); // NOI18N
        btnManagePlanesViewAdd.setName("btnManagePlanesViewAdd"); // NOI18N
        btnManagePlanesViewAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnManagePlanesViewAddActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 518, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnManagePlanesViewAdd)
                        .addGap(18, 18, 18)
                        .addComponent(btnManagePlanesViewOk, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnManagePlanesViewOk)
                    .addComponent(btnManagePlanesViewAdd))
                .addGap(28, 28, 28))
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void btnManagePlanesViewOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnManagePlanesViewOkActionPerformed
        // TODO add your handling code here:
        JFrame mainFrame = App.getApplication().getMainFrame();
        mainFrame.setContentPane(new MainPanelView());
        mainFrame.validate();
        mainFrame.repaint();



    }//GEN-LAST:event_btnManagePlanesViewOkActionPerformed

    private void btnManagePlanesViewAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnManagePlanesViewAddActionPerformed
        // TODO add your handling code here:
            if (CreateNewPlaneDialog == null){
            JFrame mainFrame = App.getApplication().getMainFrame();
            CreateNewPlaneDialog = new CreateNewPlaneDialog(mainFrame);
            CreateNewPlaneDialog.setLocationRelativeTo(mainFrame);
            }
        App.getApplication().show(CreateNewPlaneDialog);
    

    }//GEN-LAST:event_btnManagePlanesViewAddActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnManagePlanesViewAdd;
    private javax.swing.JButton btnManagePlanesViewOk;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JScrollPane jScrollPane1;
    private java.util.List<de.hdm.itproject.Plane> planeList;
    private javax.persistence.Query planeQuery;
    private javax.swing.JTable tblManagePlanesTable;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
private JDialog CreateNewPlaneDialog;
}
